import { request, useUserStore, clearEmpty } from "jmash-core";
import type { AxiosPromise } from "axios";
import type {
  JobRecordApi,
  JobRecordReq,
  JobRecordModel,
  JobRecordPage,
  JobRecordKey,
} from "./types";

class JobRecordApiImpl implements JobRecordApi {
  getKey(model: JobRecordModel): JobRecordKey {
    return {
      recordId: model.recordId,
    } as JobRecordKey;
  }

  // 查询翻页信息计划任务记录;
  findPage(query?: JobRecordReq): AxiosPromise<JobRecordPage> {
    const tenant = useUserStore().user.tenant;
    if (query) {
      query.hasState = query.state != undefined;
    }
    clearEmpty(query);
    return request({
      url: "/v1/jobs/job_record/page/" + tenant,
      method: "get",
      params: query,
    });
  }
}
const jobRecordApi = new JobRecordApiImpl();

export { jobRecordApi };
